package com.baizhi.service.impl;

import com.baizhi.dao.GuruDAO;
import com.baizhi.entity.Guru;
import com.baizhi.service.GuruService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class GuruServiceImpl implements GuruService {

    @Autowired
    private GuruDAO guruDAO;

    @Override
    public List<Guru> show() {
        return guruDAO.selectAll(null);
    }

    @Override
    public PageInfo<Guru> showAll(int page,int limit,String guruName) {
        PageHelper.startPage(page,limit);
        List<Guru> gurus = guruDAO.selectAll(guruName);
        PageInfo<Guru> pageInfo = new PageInfo<>(gurus);
        return pageInfo;
    }

    @Override
    public void add(Guru guru) {
        guruDAO.insertGuru(guru);
    }

    @Override
    public void updateStatus(int guruId, int guruStatus) {
        guruDAO.updateStatus(guruId, guruStatus);
    }

    @Override
    public void addMany(List<Guru> gurus) {
        guruDAO.insertMany(gurus);
    }

    @Override
    public List<Guru> downloadAll() {
        return guruDAO.selectAll(null);
    }
}
